/*
 * Copyright (C) 2000-2008 Jens Nixdorf and various contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies of the Software, its documentation and marketing & publicity
 * materials, and acknowledgment shall be given in the documentation, materials
 * and software packages that this Software was used.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.mopore.jat.gui;

import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

public class SingleRoundCornerRectangleFactory {
	
	public enum CornerType{ UPPER_LEFT, UPPER_RIGHT, LOWER_LEFT, LOWER_RIGHT }
	
	
	public static java.awt.Shape produceSingleRoundCornerRectangel( float x, float y, 
			float width, float height, float cWidth, float cHeight, CornerType type ) {
		
		switch ( type ) {
			case UPPER_RIGHT:{
				float cX = x + width - ( cWidth * 2 );
				float cY = y;
		
				Area circleArea = new Area( new Ellipse2D.Float( cX, cY, cWidth * 2, cHeight *2 ) );
				Area quadArea = new Area( new Rectangle2D.Float( cX + cWidth, cY, cWidth, cHeight ) );
				
				circleArea.intersect( quadArea );
				quadArea.subtract( circleArea );
				
				Area resultArea = new Area( new Rectangle2D.Float(x, y, width, height ) ); 
				resultArea.subtract( quadArea );
				
				return resultArea;
			}
			case UPPER_LEFT:{
				Area circleArea = new Area( new Ellipse2D.Float( x, y, cWidth * 2, cHeight *2 ) );
				Area quadArea = new Area( new Rectangle2D.Float( x, y, cWidth, cHeight ) );
				
				circleArea.intersect( quadArea );
				quadArea.subtract( circleArea );
				
				Area resultArea = new Area( new Rectangle2D.Float(x, y, width, height ) ); 
				resultArea.subtract( quadArea );
				
				return resultArea;
			}
			case LOWER_LEFT:{
				float cY = y + height - ( cHeight * 2 );
		
				Area circleArea = new Area( new Ellipse2D.Float( x, cY, cWidth * 2, cHeight *2 ) );
				Area quadArea = new Area( new Rectangle2D.Float( x, cY + cHeight, cWidth, cHeight ) );
				
				circleArea.intersect( quadArea );
				quadArea.subtract( circleArea );
				
				Area resultArea = new Area( new Rectangle2D.Float(x, y, width, height ) ); 
				resultArea.subtract( quadArea );
				
				return resultArea;
			}
			default:{ // LOWER_RIGHT
				float cX = x + width - ( cWidth * 2 );
				float cY = y + height - ( cHeight * 2 );
				
				Area circleArea = new Area( new Ellipse2D.Float( cX, cY, cWidth * 2, cHeight *2 ) );
				Area quadArea = new Area( new Rectangle2D.Float( cX + cWidth, cY + cHeight, cWidth, cHeight ) );
				
				circleArea.intersect( quadArea );
				quadArea.subtract( circleArea );
				
				Area resultArea = new Area( new Rectangle2D.Float(x, y, width, height ) ); 
				resultArea.subtract( quadArea );
				
				return resultArea;
			}			
		}
	}

}
